package niumao.minecraft.uhc;

import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;

public class Util {
    private static final Main plugin = Main.getPlugin(Main.class);

    public static ItemStack checkInventory(Player player, String itemName) {
        //获取某玩家的背包
        for (int i = 0; i <= 40; i++) {
            //如果该背包的位置上没有物品，则继续
            if (player.getInventory().getItem(i) == null) continue;
            ItemStack item = player.getInventory().getItem(i);
            assert item != null;
            ItemMeta itemMeta = item.getItemMeta();
            if (itemMeta == null) return null;
            if (itemMeta.getDisplayName().equalsIgnoreCase(itemName)) {
                return item;
            }
        }
        return null;
    }

    //获取Config内的自定义name
    public static String getStr(String itemName) {
        return plugin.getConfig().getString("item." + Main.getLang() + "." + itemName + ".name");
    }

    //获取Config内的自定义Lore
    public static List<String> getStr(String itemName, boolean isLore) {
        if (isLore)
            return plugin.getConfig().getStringList("item." + Main.getLang() + "." + itemName + ".lore");
        return null;
    }

    public static String getUuid(String oldId) {
        StringBuilder sb = new StringBuilder(oldId);
        sb.insert(8, '-');
        sb.insert(13, '-');
        sb.insert(18, '-');
        sb.insert(23, '-');
        return sb.toString();
    }
}
